package turrets 
{
	import org.flixel.*;
	/**
	 * ...
	 * @author morgan
	 */
	public class BurstTurret extends Turret
	{
		public var burst:int;
		public var burstRefire:Number;
		
		public var firing:Boolean = false;
		public var burstIndex:int = 0;
		public var burstTimer:Number = 0;
		
		public function BurstTurret(offx:int, offy:int, pattern:BulletPattern, type:int, angle:Number = 0, speed:Number = 100, refire:Number = 0.5, burst:int = 1, burstRefire:Number = 0) 
		{
			super(offx, offy, pattern, type, angle, speed, refire);
			this.burst = burst;
			this.burstRefire = burstRefire;
		}
		
		override public function update():void 
		{
			super.update();
			if (firing)
			{
				burstTimer -= FlxG.elapsed;
				if (burstTimer < 0)
				{
					burstIndex++
					if (burstIndex <= burst)
					{
						burstTimer = burstRefire;
						var rads:Number = fireAngle * 3.14159 / 180;
						var vx:Number = Math.cos(rads) * fireSpeed;
						var vy:Number = Math.sin(rads) * fireSpeed;
						GameState.ref.makeBullet(bulletType, x, y, vx, vy, pattern);
					}
				}
			}
		}
		
		override public function fireBullet():void 
		{
			firing = true;
			burstIndex = 0;
		}
		
	}

}